import time
import pytest
from appium import webdriver
from appium.options.android import UiAutomator2Options
from config import ANDROID_DESIRE_CAPS
from page.app_page_enter_home import pageEnterhome
from page.app_page_login import pageLogin


@pytest.fixture(scope="function")
def driver():
    """app驱动的创建及退出"""
    # 创建app驱动对象
    des_caps = ANDROID_DESIRE_CAPS
    # 初始化设备配置信息
    option = UiAutomator2Options().load_capabilities(des_caps)
    # 创建驱动对象
    driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", options=option)
    # 隐式等待
    driver.implicitly_wait(10)
    # 返回驱动对象
    yield driver
    # 暂停3秒
    time.sleep(3)
    # 关闭驱动
    driver.quit()

@pytest.fixture(scope="function",autouse=True)
def enter_home(driver):
    """全局：进入首页"""
    #创建首页对象
    time.sleep(1)
    page_home=pageEnterhome(driver)
    page_home.page_swipe_enter_home()
@pytest.fixture(scope="function")
def login(driver):
    """全局：登录"""
    #创建登录对象
    page_login=pageLogin(driver)
    #调用登录方法
    page_login.pagelogin('13811115698','w123456')